<template>
  <div class="swiper mySwiper">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="item in bannerlist" :key="item.id">
        <img :src="item.img" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import { getbanner } from "../request/api";
import "../../node_modules/swiper/js/swiper";
import Swiper from "swiper";
export default {
  data() {
    return {
      bannerlist: [],
    };
  },
  mounted() {
    getbanner()
      .then((res) => {
        // console.log(res, "成功");
        if (res.data.code == 200) {
          this.bannerlist = res.data.list;
          this.$nextTick(() => {
            new Swiper(".mySwiper", {
              loop: true,
              autoplay: {
                delay: 2000,
              },
            });
          });
        }
      })
      .catch((err) => {
        console.log(err, "错误");
      });
  },
};
</script>

<style scoped>
@import "../../node_modules/swiper/css/swiper.min.css";
.swiper {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}

.swiper-slide img {
  display: block;
  width: 100%;
  height: 315px;
  object-fit: cover;
  box-shadow: 0 0.2rem 0.2rem 0 rgba(255, 96, 64, 0.2);
}
</style>
